package com.holystone.orca.sys.service.impl;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.holystone.orca.base.service.impl.BaseServiceImpl;
import com.holystone.orca.common.PageData;
import com.holystone.orca.sys.mybatis.dao.SysCompanyMapper;
import com.holystone.orca.sys.mybatis.model.SysCompany;
import com.holystone.orca.sys.service.ISysCompanyService;

@Service("sysCompanyService")
public class SysCompanyServiceImpl extends BaseServiceImpl<SysCompany> implements ISysCompanyService{

	@Autowired
	private SysCompanyMapper sysCompanyMapper;
	
	@Override
	public PageData pagingSysCompany(int iPageNo, int iPageSize,
			String orderField, String cmpName) throws Exception {
		Map<Object, String> map=new HashMap<Object, String>();
		map.put("cmpName", cmpName);
		//map.put("personPassword",personPassword);
		//map.put("staffState",SystemConstant.STAFF_STATE_A);
		
        //分页查询
        PageHelper.startPage(iPageNo, iPageSize);
        PageInfo<SysCompany> pageInfo = new PageInfo<SysCompany>(sysCompanyMapper.getCompanyVO(map));
		PageData pageData =  new PageData();
		pageData.setPageList(pageInfo.getList());
		pageData.setTotalCount(pageInfo.getTotal());
		pageData.setPageSize(pageInfo.getPageSize());
		pageData.setPageNo(pageInfo.getPageNum());
		pageData.setTotalPage(pageInfo.getPages());
		return pageData;
	}


	@Override
	public boolean insertCompany(SysCompany sysCompany) throws Exception {
		int result=sysCompanyMapper.insertSysCompany(sysCompany);
		if(result==1){
			return true;
		}else{
			return false;
		}
		
	}

	@Override
	public boolean deleteCompany(int cmpId) throws Exception {
		int result=sysCompanyMapper.deleteCompany(cmpId);
		if(result==1){
			return true;
		}else{
			return false;
		}
		
	}

	@Override
	public List<SysCompany> selectUpdateCompany(int cmpId) throws Exception {
		List<SysCompany> list=new ArrayList<SysCompany>();
		list=sysCompanyMapper.selectUpdateCompany(cmpId);
		return list;
	}

	@Override
	public boolean updateCompany(SysCompany sysCompany) throws Exception {
		int result=sysCompanyMapper.updateCompany(sysCompany);
		if(result==1){
			return true;
		}else{
			return false;
		}
	}


	@Override
	public PageData searchCompany(int iPageNo, int iPageSize,
			String orderField, String cmpName) throws Exception {
        //分页查询
		Map<String,String> map=new HashMap<String,String>();
		map.put("cmpName", cmpName);
        PageHelper.startPage(iPageNo, iPageSize);
        PageInfo<SysCompany> pageInfo = new PageInfo<SysCompany>(sysCompanyMapper.selectCompany(map));
		PageData pageData =  new PageData();
		pageData.setPageList(pageInfo.getList());
		pageData.setTotalCount(pageInfo.getTotal());
		pageData.setPageSize(pageInfo.getPageSize());
		pageData.setPageNo(pageInfo.getPageNum());
		pageData.setTotalPage(pageInfo.getPages());
		return pageData;
	}


	@Override
	public List<SysCompany> selectCompany() {
		List<SysCompany> list = sysCompanyMapper.selectAllCompany();
		return list;
	}


	@Override
	public boolean delSelectCompany(List<Integer> list) throws Exception {
		int result=sysCompanyMapper.delSelectCompany(list);
		if(result==list.size()){
			return true;
		}else{
			return false;
		}
	}



}
